package com.lingchou.cloud.process.api.controller;

import com.lingchou.cloud.process.api.dto.result.AllTaskDTO;
import com.lingchou.cloud.process.api.dto.result.ProcessInstanceDTO;
import com.lingchou.cloud.process.api.dto.result.TaskDTO;
import com.lingchou.cloud.process.api.dto.result.base.ProcessTaskRecordVo;
import com.lc.common.bean.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.Size;
import java.util.List;
import java.util.Map;

/**
 * 流程查询API
 *
 * @author lc
 */
@RequestMapping(value = "process/v1")
@Api(value = "ProcessQueryApi", tags = "流程查询API")
@Validated
public interface ProcessQueryApi {

    /**
     * 查询发起人发起的流程实例列表
     *
     * @param userId      发起人ID
     * @param businessKey 业务Key
     * @return 流程实例列表
     */
    @ApiOperation(value = "查询发起人发起的流程实例列表", notes = "查询发起人发起的流程实例列表")
    @GetMapping("/InstanceList")
    Result<List<ProcessInstanceDTO>> instanceList(@ApiParam(name = "userId", value = "流程发起人ID") @RequestParam String userId,
                                                  @ApiParam(name = "businessKey", value = "业务Key") @RequestParam(required = false) String businessKey);

    /**
     * 查询某人员相关的未执行任务列表
     *
     * @param userId      数据归属人 或 执行人
     * @param businessKey 业务key
     * @return 任务列表
     */
    @ApiOperation(value = "查询某人员的任务列表", notes = "查询某人员的任务列表")
    @GetMapping("/taskList")
    Result<List<TaskDTO>> taskList(@ApiParam(name = "userId", value = "数据归属人 或 执行人 ID") @RequestParam String userId,
                                   @ApiParam(name = "businessKey", value = "业务Key") @RequestParam String businessKey);

    /**
     * 查询某人员相关的未执行任务列表
     *
     * @param userId      数据归属人 或 执行人
     * @param businessKey 业务key
     * @param key 模糊Key值
     * @return 任务列表
     */
    @ApiOperation(value = "查询某人员的任务列表", notes = "查询某人员的任务列表")
    @GetMapping("/taskListByKeyLike")
    Result<List<TaskDTO>> taskListByKeyLike(@ApiParam(name = "userId", value = "数据归属人 或 执行人 ID") @RequestParam String userId,
                                            @ApiParam(name = "businessKey", value = "业务Key") @RequestParam String businessKey,
                                            @ApiParam(name = "key", value = "业务Key") @RequestParam String key);

    /**
     * 查询多个人员相关的未执行任务列表
     *
     * @param userIds 数据归属人 或 执行人 集合
     * @return 任务列表
     */
    @ApiOperation(value = "查询多个人员相关的未执行任务列表", notes = "查询多个人员相关的未执行任务列表")
    @GetMapping("/taskListForUsers")
    Result<List<TaskDTO>> taskListForUsers(@ApiParam(name = "userIds", value = "数据归属人 或 执行人 ID 集合") @RequestParam List<String> userIds,
                                           @ApiParam(name = "businessKey", value = "业务Key") @RequestParam String businessKey);

    /**
     * 查询流程实例当前任务ID
     *
     * @param instanceId 流程实例ID
     * @return 任务ID
     */
    @ApiOperation(value = "查询流程实例当前任务ID", notes = "查询流程实例当前任务ID")
    @GetMapping("/taskNow")
    Result<List<TaskDTO>> taskNow(@ApiParam(name = "instanceId", value = "流程实例ID") @RequestParam String instanceId);

    /**
     * 获取任务变量
     *
     * @param taskId 任务ID
     * @return 变量Json
     */
    @ApiOperation(value = "获取任务变量", notes = "通过任务ID获取任务变量")
    @GetMapping("/getVarJsonByTask")
    Result<String> getVarJsonByTask(@RequestParam String taskId);

    /**
     * 获取所有任务节点
     *
     * @param processInstanceId 流程实例ID
     * @return 任务集合
     */
    @ApiOperation(value = "获取所有任务节点", notes = "获取所有任务节点")
    @GetMapping("/getAllTask")
    Result<List<AllTaskDTO>> getAllTask(@RequestParam String processInstanceId);

    /**
     * 查询流程履历
     *
     * @return 流程记录
     */
    @ApiOperation(value = "查询流程履历", notes = "查询流程履历")
    @GetMapping("/getRecord")
    Result<List<ProcessTaskRecordVo>> getRecord(@ApiParam(name = "processInstanceId", value = "流程实例ID")
                                                @RequestParam String processInstanceId);


    /**
     * 批量查询流程履历
     *
     * @param processInstanceIds 流程实例ID列表
     * @return 履历列表
     */
    @ApiOperation(value = "批量查询流程履历", notes = "批量查询流程履历")
    @GetMapping("/queryRecordBatch")
    Result<Map<String, List<ProcessTaskRecordVo>>> queryRecordBatch(@ApiParam(name = "processInstanceIds", value = "流程实例ID列表")
                                                                    @RequestParam @Size(max = 100, message = "介于性能问题，查询量应小于100")
                                                                            List<String> processInstanceIds);


    /**
     * 查询最后一个审批人
     *
     * @param processInstanceId 流程实例ID
     * @return 最后一个审批人人员编号
     */
    @ApiOperation(value = "查询最后一个审批人", notes = "查询最后一个审批人")
    @GetMapping("/getLastApprover")
    Result<String> getLastApprover(@ApiParam(name = "processInstanceId", value = "流程实例ID")
                                   @RequestParam String processInstanceId);

    /**
     * 判断最后一个节点
     *
     * @param taskId 任务ID
     * @return 如果是最后一个节点返回 true 否则 false
     */
    @ApiOperation(value = "判断最后一个节点", notes = "判断最后一个节点")
    @GetMapping("/judgeTheLastNode")
    Result<Boolean> judgeTheLastNode(@ApiParam(name = "taskId", value = "任务ID")
                                     @RequestParam String taskId);

    /**
     * 查询任务的节点类型
     *
     * @param taskId 任务ID
     * @return 返回任务的节点类型
     */
    @ApiOperation(value = "查询任务的节点类型", notes = "查询任务的节点类型")
    @GetMapping("/queryNodeType")
    Result<String> queryNodeType(@ApiParam(name = "taskId", value = "任务ID")
                                 @RequestParam String taskId);
}
